﻿using CommunityToolkit.Mvvm.Input;
using NewWms.Apiservice;
using NewWms.Apiservice.Dto;
using NewWms.Apiservice.InPut;
using Prism.Mvvm;
using Prism.Regions;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NewWms.ViewModels
{
    public partial class MaterialBaseViewMode : BindableBase, INavigationAware
    {





        private Prism.Services.Dialogs.IDialogService Dialog;
        private readonly IBaseService baseService;
        private readonly IViewService viewService;
        public MaterialBaseViewMode(Prism.Services.Dialogs.IDialogService dialog)
        {
            baseService = new BaseService();
            viewService = new ViewService();
            MaterialPropertyhDtos = new List<MaterialPropertyhDto>();
            InPut_ViewService8=new InPut_ViewService8();
            Dialog = dialog;
            InPut_ViewService8.PageIndex = 1;
            InPut_ViewService8.PageSize = 50;
        }
        private List<MaterialPropertyhDto> materialPropertyhDtos;
        public List<MaterialPropertyhDto> MaterialPropertyhDtos
        {
            get { return materialPropertyhDtos; }
            set { materialPropertyhDtos = value;RaisePropertyChanged(); }
        }
        private InPut_ViewService8 inPut_ViewService8;
        public InPut_ViewService8 InPut_ViewService8
        {
            get { return inPut_ViewService8; }
            set { inPut_ViewService8 = value;RaisePropertyChanged(); }
        }
        private long count;
        public long Count
        {
            get { return count; }
            set { count = value; RaisePropertyChanged(); }
        }
        private long pagecount;
        public long PageCount
        {
            get { return pagecount; }
            set { pagecount = value; RaisePropertyChanged(); }
        }



        //导入物料
        [RelayCommand]
        private  void ExcelImportMaterialProperty()
        {
            ExcelImport.ExcelImportMaterialProperty();
        }
        //物料视图
        [RelayCommand]
        private async void View_MaterialProperty()
        {


            Tuple<List<MaterialPropertyhDto>, long?, long?> tuple = await viewService.View_MaterialProperty(InPut_ViewService8);
            if (tuple.Item1 != null)
            {
                MaterialPropertyhDtos = tuple.Item1;
                Count = (long)tuple.Item2;
                PageCount = (long)tuple.Item3;
            }
        }
        //添加物料
        [RelayCommand]
        private async void CreateMaterialProperty()
        {
            Dialog.ShowDialog("CreateMaterialPropertyDialog");
        }


        //主页设置
        private string title = "基础物料";
        public string Title
        {
            get { return title; }
            set { title = value; RaisePropertyChanged(); }
        }
        public bool IsNavigationTarget(NavigationContext navigationContext)
        {
            return true;
        }
        public void OnNavigatedFrom(NavigationContext navigationContext)
        {
           
        }
        public void OnNavigatedTo(NavigationContext navigationContext)
        {
            View_MaterialProperty();
        }
    }
}
